package com.worthtech.billportal.dao.hibernate;

import java.sql.Connection;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.worthtech.billportal.bean.SamcardInfo;
import com.worthtech.billportal.bean.WtTrainsLimit;
import com.worthtech.billportal.dao.LimitDAO;

public class LimitHibernateDAO extends HibernateDaoSupport implements LimitDAO {

	public void saveLimit(WtTrainsLimit limit) {
		this.getHibernateTemplate().save(limit);
	}
	
	public List selObj(String tablename,int startPage, int perNo,String sql) {
		String hql = "from " + tablename + " " + sql;
		System.out.println("hql2=" + hql);
		if (perNo == 0) {
			return this.getSession().createQuery(hql).list();
		}
		return this.getSession().createQuery(hql).setFirstResult(startPage)
				.setMaxResults(perNo).list();
	}

	public String getCount(String tableName, String condition) {
		String hql = "select count(*) from " + tableName + " " + condition;
		System.out.println("hql1=" + hql);
		String tmp = this.getSession().createQuery(hql).list().get(0)
				.toString();
		System.out.println("count=" + tmp);
		return tmp;
	}

	public void updateLimitinfo(WtTrainsLimit limit){
		this.getHibernateTemplate().update(limit);
		System.out.println("updatedao");
	}

	public void delLimitInfo(WtTrainsLimit limit) {
		this.getHibernateTemplate().delete(limit);
	}

	public List getInfo(String tableName, String condition) {
		String sql ="from "+tableName+" "+condition;
		System.out.println("hql="+sql);
		List list = this.getSession().createQuery(sql).list();
		//Connection con = this.getSession().connection();
		//List list = null;
		return list;
	}
}
